package my.webservices;

import javax.jws.HandlerChain;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import my.webservices.beans.UserCredentials;
import my.webservices.beans.UserDetails;
import my.webservices.beans.UserRoles;
import my.webservices.exceptions.UserNotFoundException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Seema Khattar
 * 
 */
@WebService(name="AuthenticationService", targetNamespace = "http://my/vhs/security/webservice", serviceName="authenticationService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@HandlerChain(file = "handlers.xml")
public class AuthenticationServiceImpl implements AuthenticationService {

	private final static Logger LOGGER = LoggerFactory.getLogger(AuthenticationServiceImpl.class);
	
	@WebMethod
	public UserDetails getAuthenticUserDetails(UserCredentials credentials)
			throws UserNotFoundException {
		LOGGER.debug("Credentials ={}",credentials);
		//TODO: Remove after Ldap validation is added
		UserDetails details = new UserDetails();
		details.setName("Administrator");
		UserRoles roleAdmin = new UserRoles();
		roleAdmin.setName("ROLE_ADMIN");
		UserRoles roleUser = new UserRoles();
		roleUser.setName("ROLE_USER");
		details.setRoles(new UserRoles[] { roleAdmin, roleUser });
		details.setAccountNonExpired(true);
		details.setAccountNonLocked(true);
		details.setCredentialsNonExpired(true);
		details.setEnabled(true);
		return details;
	}

}
